from qiniu import Auth, put_file, etag
import qiniu.config

# 需要填写你的 Access Key 和 Secret Key
access_key = '9diXEnGacOiik37_3r9KKs-XKmOxmcFD6y5awh9t'
secret_key = 'joP1W5lsGyFl8S3r6FlDoGQFeur3CZsWOaQSex7a'

# 构建鉴权对象
q = Auth(access_key, secret_key)

# 要上传的空间
bucket_name = 'timers-site'


# 上传文件
def upload(key, file_path):
    # 生成上传 Token，可以指定过期时间等
    token = q.upload_token(bucket_name, key, 3600)
    ret, info = put_file(token, key, file_path, version='v2')
    # print(info)
    assert ret['key'] == key
    assert ret['hash'] == etag(file_path)
